package cn.jlonely.xyhx.admin.service.impl;

import cn.jlonely.xyhx.admin.service.NotificationService;
import cn.jlonely.xyhx.pojo.Notification;
import cn.jlonely.xyhx.pojo.User;
import cn.jlonely.xyhx.utils.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.jlonely.xyhx.admin.mapper.NotificationMapper;

import java.util.List;

@Service
public class NotificationServiceImpl implements NotificationService {

    @Autowired
    private NotificationMapper notificationMapper;

    /**
     * 获取通知分页
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public PageResult<Notification> getNotificationPage(Integer page, Integer pageSize) {

        PageHelper.startPage(page, pageSize);

        List<Notification> notifications = notificationMapper.getNotificationPage();

        Page<Notification> n = (Page<Notification>) notifications;

        return new PageResult<>(n.getTotal(), n.getResult());

    }

    /**
     * 删除通知
     * @param id
     */
    @Override
    public void deleteNotification(Integer id) {
        notificationMapper.deleteNotification(id);
    }

    /**
     * 创建通知
     * @param notification
     */
    @Override
    public void createNotification(Notification notification) {
        notificationMapper.createNotification(notification);
    }
}
